package com.etv.launcher.ui.actvity;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.etv.launcher.model.entity.ApplicationInfoEntity;
import com.etv.launcher.repository.ApplicationInfoRepository;

import java.util.List;
import java.util.concurrent.Executors;

import javax.inject.Inject;

import dagger.hilt.android.lifecycle.HiltViewModel;
import lombok.Getter;

@Getter
@HiltViewModel
public class MainActivityViewModel extends ViewModel {

    private final ApplicationInfoRepository infoRepository;

    private final LiveData<List<ApplicationInfoEntity>> appsLiveData;

    private final MutableLiveData<Boolean> finishPreInit;

    @Getter
    private final LiveData<Float> batteryLiveData;

    @Inject
    public MainActivityViewModel(ApplicationInfoRepository infoRepository){
        this.infoRepository = infoRepository;
        this.appsLiveData = infoRepository.getAppListLiveData();
        this.finishPreInit = new MutableLiveData<>();
        this.batteryLiveData = infoRepository.getBatteryLiveData();
    }

    public void loadApplicationInfo(){
        Executors.newSingleThreadExecutor().execute(()->{
            infoRepository.loadApplicationInfo();
            finishPreInit.postValue(true);
        });
    }

}
